package javase.ch05.homeWork.Demo2;

import java.io.*;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {
        //客户端：将本地文件上传到服务器。接收服务器的反馈
        //服务器端：将接收到的文件保存到指定目录下，并返回上传成功


        //1.创建Socket对象，连接服务器
        Socket socket = new Socket("127.0.0.1", 10086);

        //2.读取本地文件，并写到服务器中
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("C:\\Users\\李瑞\\Desktop\\Code\\JavaSE\\Test\\BaGuangGeiDiJia.png"));
        BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
        byte[] bytes = new byte[1024];
        int len;
        while((len = bis.read(bytes)) != -1){
            bos.write(bytes,0,len);
        }

        socket.shutdownOutput();

        //4.接收服务器反馈
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        System.out.println(br.readLine());

        //3.关闭流和socket

        socket.close();
    }
}
